package com.goldze.mvvmhabit.ui.quicklogin;

import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;

import com.bumptech.glide.Glide;
import com.goldze.mvvmhabit.BR;
import com.goldze.mvvmhabit.R;
import com.goldze.mvvmhabit.app.AppViewModelFactory;
import com.goldze.mvvmhabit.databinding.ActivityQuickRegisterBinding;
import com.goldze.mvvmhabit.utils.RetrofitClient;
import com.goldze.mvvmhabit.utils.UserManager;

import me.goldze.mvvmhabit.base.BaseActivity;

/**
 * 一个MVVM模式的登陆界面
 */
public class QuickRegisterActivity extends BaseActivity<ActivityQuickRegisterBinding, QuickRegisterViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_quick_register;
    }

    @Override
    public int initVariableId() {
            return BR.viewModel;
    }

    @Override
    public QuickRegisterViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用LoginViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(QuickRegisterViewModel.class);
    }

    @Override
    public void initViewObservable() {
    }

    @Override
    public void initData() {
        super.initData();
        if (UserManager.getAppManager().getmCompany() != null && UserManager.getAppManager().getmCompany().getLogo() != null) {
            Glide.with(this).load(RetrofitClient.baseUrl + UserManager.getAppManager().getmCompany().getLogo()).into(binding.quickLoginHeadCiv);
        } else {
            binding.quickLoginHeadCiv.setImageResource(R.mipmap.default_head_icon);
        }
    }
}
